﻿using Microsoft.AspNetCore.Mvc;
using NuGet.Packaging.Signing;
using System.Threading.Tasks;
using WMS.Pagination;
using WMS.StorageManagement.RepositoryDefinitions;
using WMS.StorageManagement.RepositoryDefinitions.Dto;

namespace WMS.Web.Controllers.StorageManagement.RepositoryDefinitions
{
    public class RepositoryDefinitionController : Controller
    {
        /// <summary>
        /// 仓库定义服务接口
        /// </summary>
        private readonly IRepositoryDefinitionAppService _repositoryDefinitionAppService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="repositoryDefinitionAppService">仓库定义服务接口</param>
        public RepositoryDefinitionController(IRepositoryDefinitionAppService repositoryDefinitionAppService)
        {
            _repositoryDefinitionAppService = repositoryDefinitionAppService;
        }

        /// <summary>
        /// 显示视图
        /// </summary>
        /// <returns>跳转到视图</returns>
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 添加仓库定义信息
        /// </summary>
        /// <param name="repositoryDefinitionDto">仓库定义Dto</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Insert(RepositoryDefinitionDto repositoryDefinitionDto)
        {
            var reslut=await _repositoryDefinitionAppService.Insert(repositoryDefinitionDto);
            return reslut;
        }
        /// <summary>
        /// 显示仓库定义信息
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="repositoryName">仓库名称</param>
        /// <returns>返回结果</returns>
        [HttpGet]
        public async Task<PageResult> GetList(int pageIndex, int pageSize, string? repositoryName)
        {
            var list = await _repositoryDefinitionAppService.GetInquire(pageIndex, pageSize, repositoryName);
            return list;
        }
        /// <summary>
        /// 删除仓库定义信息
        /// </summary>
        /// <param name="ids">仓库定义编号</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Deleted(string ids)
        {
            var reslut = await _repositoryDefinitionAppService.Deleted(ids);
            return reslut;
        }

        /// <summary>
        /// 编辑客户信息
        /// </summary>
        /// <param name="repositoryDefinitionDto">仓库定义Dto</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Update(RepositoryDefinitionDto repositoryDefinitionDto)
        {
            var reslut = await _repositoryDefinitionAppService.Update(repositoryDefinitionDto);
            return reslut;
        }
    }
}
